import { getBreadCrumbList, getHomeRoute } from "@/libs/util";

import config from "@/config";
import paramSetupServer from "@/api/system_high/paramSetupServer";

const { homeName } = config;

export default {
  state: {
    sysFormModel: { title: "", logoUrl: "" },
    breadCrumbList: [],
    homeRoute: {},
    isBulid: false
  },
  getters: {
    sysFormModel: state => state.sysFormModel,
    breadCrumbList: state => state.breadCrumbList,
    homeRoute: state => state.homeRoute,
    isBulid: state => state.isBulid
  },
  mutations: {
    setBreadCrumb(state, route) {
      state.breadCrumbList = getBreadCrumbList(route, state.homeRoute);
    },
    setHomeRoute(state, routes) {
      state.homeRoute = getHomeRoute(routes, homeName);
    },
    setSysTitle(state, reload) {
      state.sysFormModel = reload;
    },
    setBulid(state, reload) {
      state.isBulid = reload;
    }
  },
  actions: {
    async getSysTitle({ state, commit }) {
      let formModel = {
        title: "智能代码平台",
        logoUrl: require("../../assets/images/logo.png")
      };

      let res1 = await paramSetupServer.getOne("sys_title");
      if (res1.data) {
        formModel.title = res1.data.value;
        document.title = res1.data.value;
      }
      let res2 = await paramSetupServer.getOne("sys_logo");
      if (res2.data) {
        formModel.logoUrl = res2.data.value;
      }

      commit("setSysTitle", formModel);
    }
  }
};
